#ifndef SCENE0_H
#define SCENE0_H

//LOADING SCREEN
//This is where we can load in our system resources while rendering a loading screen.

int Load_Batch = 0; //The batch until next load change
char* Load_String;  //Loading text
float Logo_Pause_Time = .1; //Time paused between logo screens
float Game_Pause_Time = .1;
//Frame Functions
bool Scene0FrameFunc()
{ 
 Collect_Time_Data(Delta_Time, Elapsed_Time, Current_FPS);
 switch(Load_Batch)
 {
  case 0:
   Load_String = new char[255];
   Load_Graphic(Tex_Load_Screen  , "Gfx\\GUI_Gfx\\LoadScreen.png", Spr_Load_Screen   , 1024, 768);
   Load_Graphic(Tex_Load_Bar     , "Gfx\\GUI_Gfx\\LoadBar.png"   , Spr_Load_Bar      ,   64,  64, 0, 0, 0, 0, 0x50FFFFFF);
   Load_Graphic(Tex_Load_Frame   , "Gfx\\GUI_Gfx\\LoadFrame.png" , Spr_Load_Frame    ,  320,  64);
   Load_Graphic(Tex_Empty_Cell   , ""                            , Spr_Empty_Cell    , 1024, 768, 0, 0, 0, 0, 0x00FFFFFF);
   Load_Fonts(Ariel_Font, "Gfx\\Fonts\\arial.fnt", 0xFF000000);
   Load_String = "Initializing...";
   Load_Batch++;
  break; 
  case 1:
   Load_String = "Loading Graphics";
   Load_Graphic(Tex_Load_Logo    , "Gfx\\GUI_Gfx\\LoadLogo.png"   ,         Spr_Load_Logo,  500, 500, 0, 0, 250, 250, 0x00FFFFFF);
   Load_Graphic(Tex_Load_Studio  , "Gfx\\GUI_Gfx\\LoadStudio.png" ,       Spr_Load_Studio,  500, 500, 0, 0, 250, 250, 0x00FFFFFF);
   Load_Graphic(Tex_Char1_Head   , "Gfx\\Player_Gfx\\Character1_Head.png"   , Spr_Char1_Head,  64, 64, 0, 0, 32, 32, 0xFFFFFFFF);   
   Load_Graphic(Tex_Char1_Arm1   , "Gfx\\Player_Gfx\\Character1_Arm1.png"   , Spr_Char1_Arm1,  64, 64, 0, 0, 32, 32, 0xFFFFFFFF);   
   Load_Graphic(Tex_Char1_Body   , "Gfx\\Player_Gfx\\Character1_Body.png"   , Spr_Char1_Body,  64, 64, 0, 0, 32, 32, 0xFFFFFFFF);   
   Load_Animation(Tex_Char1_Feet , "Gfx\\Player_Gfx\\Character1_Feet.png"   , Ani_Char1_Feet,  10,  8, 0, 0, 64, 64, 32, 32, 0xFFFFFFFF);
   Load_Graphic(Tex_Fire_Cursor  , "Gfx\\GUI_Gfx\\Fire_cursor.png" ,      Spr_Fire_Cursor,  32, 32, 0, 0, 16, 16, 0xFFFFFFFF);            
   Load_Graphic(Tex_Bg_Grid      , "Gfx\\GUI_Gfx\\bggrid.jpg"    ,          Spr_Bg_Grid,  300, 300, 0, 0);
   Load_Graphic(Tex_Grass_512    , "Gfx\\Textures\\Texture_Grass_512.png" , Spr_Grass1_512, 512, 512,   0,   0, 256, 256, 0xFFFFFFFF);   
   Load_Graphic(Tex_Grass_512    , "Gfx\\Textures\\Texture_Grass_512.png" , Spr_Grass1_256, 256, 256,   0,   0, 128, 128, 0xFFFFFFFF);
   Load_Graphic(Tex_Grass_512    , "Gfx\\Textures\\Texture_Grass_512.png" , Spr_Grass2_256, 256, 256, 256,   0, 128, 128, 0xFFFFFFFF);
   Load_Graphic(Tex_Grass_512    , "Gfx\\Textures\\Texture_Grass_512.png" , Spr_Grass3_256, 256, 256,   0, 256, 128, 128, 0xFFFFFFFF);
   Load_Graphic(Tex_Grass_512    , "Gfx\\Textures\\Texture_Grass_512.png" , Spr_Grass4_256, 256, 256,  32,  32,  16,  16, 0xFFFFFFFF);      
   Load_Batch++;
  break;                 
  case 2:  
   Load_String = "Loading Players";
   CharacterA = new Player(Spr_Char1_Head, Spr_Char1_Arm1, Spr_Char1_Body, Ani_Char1_Feet);
   Load_Batch++;
  break;                 
  case 3:  
   Load_String = "Loading Particle Systems";
   Load_Batch++;
  break;                 
  case 4:    
   Load_String = "Loading Weapons";
   //Load_MG_Weapons();
   //---------------------------------------------------
   //WEAPONS (Soon to be replaced by parser)
   //Submachine gun
   Submachine_Gun_1->weapon_name            = "Submachine Gun";
   Load_Graphic(Tex_Submachine_Gun_1, "Gfx\\Weapons\\Weapon_Sub1gun.png", Spr_Submachine_Gun_1, 64, 32, 0, 0, 32, 16, 0xFFFFFFFF);
   Load_Graphic(Tex_Submachine_Bullet_1, "Gfx\\Weapons\\Weapon_Sub1bullet.png", Spr_Submachine_Bullet_1, 16, 16, 0, 0, 8, 8, 0xFFFFFFFF);
   Load_Graphic(Tex_Submachine_Cart_1, "Gfx\\Weapons\\Weapon_Sub1Cartridge.png", Spr_Submachine_Cart_1, 16, 16, 0, 0, 8, 8, 0xFFFFFFFF);
   Load_Graphic(Tex_Submachine_Casing_1, "Gfx\\Weapons\\Weapon_Sub1Casing.png", Spr_Submachine_Casing_1, 16, 16, 0, 0, 8, 8, 0xFFFFFFFF);   
   Submachine_Gun_1->GunSprite              = Spr_Submachine_Gun_1;
   Submachine_Gun_1->BulletSprite           = Spr_Submachine_Bullet_1;
   Submachine_Gun_1->Cartridge              = Spr_Submachine_Cart_1;
   Submachine_Gun_1->Casing                 = Spr_Submachine_Casing_1;
   Submachine_Gun_1->weapon_weight          = 2.977; //This is 2.977kg, the standard weight of a submachine gun based on the H&K Mp5
   Submachine_Gun_1->ammo_count             = 30;
   Submachine_Gun_1->cur_ammo               = 30;
   Submachine_Gun_1->shells_per_shot        = 1;
   Submachine_Gun_1->spread_factor          = 0; //This is a random spreading that occurs for weapons that fire many shells. Use Accuracy to model weapon inaccuracies
   Submachine_Gun_1->base_reload            = 2.25;
   Submachine_Gun_1->fire_type              = 1; //Automatic
   Submachine_Gun_1->fire_rate              = .05; //10 rounds per second
   Submachine_Gun_1->muzzle_radius          = 20; //20 pixels offset from body to muzzle.
   Submachine_Gun_1->base_damage            = 20; //Out of a 100 health scale, 20 seems like a reasonzble base damage value.
   Submachine_Gun_1->bullet_caliber         = 2;  //The pixel radius of the actual bullet, affects collsion
   Submachine_Gun_1->base_velocity          = 1200; //1200 pixels per second exit velocity
   Submachine_Gun_1->base_acceleration      =  -20; //For each second, the speed of the bullet drops by 20. When velocity reaches the dropoff, the bullet disappears.
   Submachine_Gun_1->velocity_damage_factor =  1.0; //Describes the effect that bullet slowdown has on the actual damage of the bullet. For conventional weapons, this value is close to 1, whereas for energy weapons, the value is close to 0.
   Submachine_Gun_1->armor_piercing_factor  =  .05; //Describes the piercing ability of the projectile. For this example, for every armor point, 5 percent is reduced from the total damage. At armor levels 20 to 40, a base damage of 1 is applied. At armor levels greater then 40, this weapon is not effective.
   Submachine_Gun_1->affected_by_player_movement = true; //Describes whether this weapon is affected by newtonian physics.
   Submachine_Gun_1->base_accuracy          =    3;  //Inaccuracies in degrees. This is what you would expect on the first shot while not moving.
   Submachine_Gun_1->speed_bink_factor      =   .50; //The penalty factor of inaccuracy compounded by the player moving.
   Submachine_Gun_1->accuracy_dropoff       =   .35; //Compounded inaccuracy per shot in degrees.
   Submachine_Gun_1->accuracy_gain          =  2.55; //You want this value lower then the amount your accuracy drops off, or your weapon will not be inaccurate. 
   Submachine_Gun_1->bullet_dropoff_time    =    10; //Amount of time in seconds the bullet is in play.
   Submachine_Gun_1->velocity_dropoff       =     0;
   Submachine_Gun_1->Is_Bouncy = false; Submachine_Gun_1->Is_Flaming = false; Submachine_Gun_1->Is_Poison = false;
   Submachine_Gun_1->Is_Paralysis = false; Submachine_Gun_1->Is_Ionic = false; Submachine_Gun_1->Is_Piercing = false;
   Submachine_Gun_1->Bounce_Num = 0; Submachine_Gun_1->Flame_DPS = 0; Submachine_Gun_1->Poison_DPS = 0;
   Submachine_Gun_1->Paralysis_Time = 0; Submachine_Gun_1->Ion_Dist = 0; Submachine_Gun_1->Pierce_Num = 0;
   
   CharacterA->Cur_Gun = new Inventory_Gun(CharacterA, Submachine_Gun_1); //Equip the character with a submachine gun.

   Load_Batch++;
  break;                 
  case 5:       
   Load_String = "Loading Buildings";
   Load_Batch++;
  break;                 
  case 6:       
   Load_String = "Loading Enemies";
   Spider_1->critter_name          = "Brown Spider";
   Spider_1->spr_critter_attack    = Spr_Char1_Head;
   Spider_1->spr_critter_movement  = Spr_Char1_Head;
   Spider_1->min_health            =   80;
   Spider_1->max_health            =  120;
   Spider_1->Phys_Res              = 1.00;
   Spider_1->Fire_Res              = 1.00;
   Spider_1->Poison_Res            = 1.00;
   Spider_1->Para_Res              = 1.00;
   Spider_1->Ionic_Res             = 1.00;
   Spider_1->Pierce_Res            = 1.00;
   Spider_1->Low_Caliber_Res       = 1.00;
   Spider_1->min_weight            =   10;
   Spider_1->max_weight            =   15;
   Spider_1->HitBoxA_Radius        =   32;
   Spider_1->HitBoxA_Damage_Factor = 1.00;
   Spider_1->offsetA_X             =    0;
   Spider_1->offsetA_Y             =    0;
   Spider_1->HitBoxB_Radius        =   32;
   Spider_1->HitBoxB_Damage_Factor = 1.00;
   Spider_1->offsetB_X             =    0;
   Spider_1->offsetB_Y             =    0;
   Spider_1->HitBoxC_Radius        =   32;
   Spider_1->HitBoxC_Damage_Factor = 1.00;
   Spider_1->offsetC_X             =    0;
   Spider_1->offsetC_Y             =    0;   
/*
 //AI & Abilities (MUST IMPLEMENT)
 bool Burrow, Sprint, Reanimate, Berserk, Explode, Split, Sappervore, Chameleon, Projectile;
*/   
   Load_Batch++;
  break;                 
  case 7:       
   Load_String = "Loading Sounds";
   Load_Batch++;
  break;                 
  case 8:       
   Load_String = "Loading Maps";
   //Replace 500 with a configurable init file parse
   max_action_prop = 500;
   max_static_prop = 5000;
   Action_Props = new Action_Prop[max_action_prop];
   Static_Props = new Static_Prop[max_static_prop];
   top_prop = 1;
   Load_Batch++;
  break;                 
  case 9:       
   Load_String = "Starting Game";
   //Create graphics for the main menu
   Load_Graphic(Tex_MainMenuBG,  "Gfx\\GUI_Gfx\\MainMenuBG.jpg",     Spr_MainMenuBG,  1024, 768, 0,  0, 0, 0, 0xFFFFFFFF);
   Load_Graphic(MainMenuButton1, "Gfx\\GUI_Gfx\\MainMenuButton1.png", Start_Game_On,   128,  32, 0,  0, 0, 0, 0xFFFFFFFF);
   Load_Graphic(MainMenuButton1, "Gfx\\GUI_Gfx\\MainMenuButton1.png", Start_Game_Off,  128,  32, 0, 32, 0, 0, 0xFFFFFFFF, true);   
   Load_Graphic(MainMenuButton1, "Gfx\\GUI_Gfx\\MainMenuButton1.png", Exit_Game_On,    128,  32, 0,  0, 0, 0, 0xFFFFFFFF, true);
   Load_Graphic(MainMenuButton1, "Gfx\\GUI_Gfx\\MainMenuButton1.png", Exit_Game_Off,   128,  32, 0, 32, 0, 0, 0xFFFFFFFF, true);    
   CreateButton(Start_Game, Start_Game_On, Start_Game_Off, 50, 300, 1);
   CreateButton( Exit_Game,  Exit_Game_On,  Exit_Game_Off, 50, 350, 1);
   Load_Batch++;
  break;                                        
  case 10:
  if(GETA(Spr_Empty_Cell->GetColor()) != 255)   //Fading in the studio logo
   {
    Fade_up(Spr_Empty_Cell, 5); Fade_up(Spr_Load_Studio, 5);
    if(hge->Input_GetKeyState(HGEK_ESCAPE)) {Fade_up(Spr_Empty_Cell, 255); Fade_up(Spr_Load_Studio, 255); Logo_Pause_Time = .5;}
   }
  else                                          //Fading in the game logo
   { 
     if(Pause_Function(Logo_Pause_Time, Delta_Time)) 
      {
       Fade_down(Spr_Load_Studio, 5); Fade_up(Spr_Load_Logo, 4); 
       if(hge->Input_GetKeyState(HGEK_ESCAPE)) {Fade_down(Spr_Load_Studio, 255); Fade_up(Spr_Load_Logo, 255); Game_Pause_Time = .5;}
       if(GETA(Spr_Load_Logo->GetColor()) == 255 && Pause_Function(Game_Pause_Time, Delta_Time)) {Change_Scene(1);}
      }
   }
  break;
 }
 return false;
}

bool Scene0RenderFunc()
{ 
 hge->Gfx_BeginScene();
 hge->Gfx_Clear(0xFFFFFFFF);
 if(Load_Batch >= 1) 
  {
   Spr_Load_Screen->Render(0, 0); Spr_Load_Frame->Render(352, 400);
   Ariel_Font->printf(50, 725, HGETEXT_LEFT, Load_String);
  }
 for(int i = 0; i + 1 < Load_Batch; i++) {Spr_Load_Bar-> Render(352 + i*32, 400);} //Progress Bar
 if(Load_Batch == 10) 
  {
   Render_Texture_Field(Spr_Bg_Grid, 0, 0, Screen_Width, Screen_Height, 0, 0);
   //Spr_Empty_Cell  -> Render(0, 0);
   Spr_Load_Logo   -> Render(Screen_Width/2, Screen_Height/2);
   Spr_Load_Studio -> RenderEx(Screen_Width/2, Screen_Height/2, 0, .7, .7);
   Report_Status(Ariel_Font, Screen_Width - 100, 10, Delta_Time, Current_FPS, Elapsed_Time, .5, 0xFF000000);
   Ariel_Font->printf(10, 10, HGETEXT_LEFT, "Current Alpha: %i", GETA(Spr_Load_Logo->GetColor()));
  }
 hge->Gfx_EndScene();
 return false; 
}

#endif
